import React, { useEffect, useState } from "react";
import { queryPostDetailById } from "@/services/post";
import Taro from "@tarojs/taro";
import { getCurrentInstance } from "@tarojs/taro";

function UseDetail() {
  const [mdContent, setMdContent] = useState("");
  const getDetail = async (id = "") => {
    const { status, content = {}, msg = "" } = await queryPostDetailById(id);
    if (status) {
      setMdContent(content?.content ?? "");
      Taro.setNavigationBarTitle(content?.title ?? "");
    } else {
      console.log(msg);
    }
  };

  useEffect(() => {
    const { router } = getCurrentInstance();
    const { params } = router || {};
    getDetail(params?.id);
  }, []);
  return { mdContent };
}

export default UseDetail;
